<?php
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
function getlang(){
		$lang = $_SESSION['lang'];
		if (empty($lang) || $lang == "EN") {
			$value = "../value/value_en.php";
		} else if($lang == "VN") {
			$value = "../value/value_vn.php";
		}
		else {
			$value = "../value/value_kr.php";
		}
		return $value;
	}
include '../connection/connection.php';	
$value = getlang();
$list=$_SESSION['sort'];
include($value);
	$page=$_GET['pages'];
	$str=$_GET['str'];
	$_SESSION['sortn']=$str;
	$flagDesc=$_GET['flagDesc'];
	
	$search=$_REQUEST['search'];
	$from=$_REQUEST['from'];
	$to=$_REQUEST['to'];
	$lstatus=$_REQUEST['status'];
	$oneday=$_REQUEST['oneday'];
	$twodays=$_REQUEST['twodays'];
	$oneweek=$_REQUEST['oneweek'];
	$onemonth=$_REQUEST['onemonth'];
	
	$searchhostnameauto = $_REQUEST['searchhostnameauto'];
	
	$rows_per_page = 20 ;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	if($flagDesc==1){

		if($list[$str]=="DESC")
			$list[$str]="ASC";
		else
			$list[$str]="DESC";
	}
	
	$sql = "SELECT ls.*,ui.email FROM `user_info` ui, log_server ls WHERE ls.id = ui.id AND ls.server_name LIKE '%".$searchhostnameauto."%' ";
	
	if ($_REQUEST['from'] != '' && $_REQUEST['to'] != ''){
		$sql.=" and ls.ins_time >='".$_REQUEST['from']." 00:00:00' AND ls.ins_time<='".$_REQUEST['to']." 23:59:59'";
	}else{
		if ($_REQUEST['from'] != ''){
			$sql.=" and ls.ins_time >='".$_REQUEST['from']." 00:00:00' and ls.ins_time<='".$_REQUEST['from']." 23:59:59'";
		}else if ($_REQUEST['to'] != ''){
			$sql.=" and ls.ins_time >='".$_REQUEST['to']." 00:00:00' and ls.ins_time<='".$_REQUEST['to']." 23:59:59'";
		}
	}
	
	
	if ($_REQUEST['status'] != '' && $_REQUEST['status'] != 'all'){
		$sql.= " AND ls.`status` ='".$_REQUEST['status']."'";
	}
	
	$selectlogserver = mysql_query($sql." ORDER BY ".$str." ".$list[$str]);
	$number_of_page = ceil ( mysql_num_rows( $selectlogserver ) / $rows_per_page );

	$_SESSION['sort']=$list;
	?>
	<thead>
			<tr>
				<td align="center" style="color: #696969;width: 4%"><?php echo $no?></td>
				<td align="center"><a onclick="sortandpagingLogServer('<?=$page?>','ui.email',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $useriforid?></a></td>
				<td align="center"><a onclick="sortandpagingLogServer('<?=$page?>','ls.server_ip',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteserverip ?></a></td>
				<td align="center">
					<a onclick="sortandpagingLogServer(<?=$page?>,'ls.server_name',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteserverhostname?></a>
					<input type="text" style="width: 150px;height: 24px;border: 1px red solid;padding-left: 5px;" id="searchHostName" name="searchHostName"  value="<?=$searchhostnameauto?>"
					onkeyup="sortandpagingLogServer(<?=$page?>,'ls.server_name',1,'<?=$search?>','<?=$searchfrom?>','<?=$searchto?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>',this.value)">
					</td>
				<td align="center"><a onclick="sortandpagingLogServer(<?=$page?>,'ls.version',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteserverver?></a></td>
				<td align="center"><a onclick="sortandpagingLogServer(<?=$page?>,'ls.status',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $status?></a></td>
				<td align="center"><a onclick="sortandpagingLogServer(<?=$page?>,'ls.server_time',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $remoteservertime?></a></td>
				<td align="center"><a onclick="sortandpagingLogServer(<?=$page?>,'ls.ins_time',1,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" style="cursor: pointer;color: #027acc"><?php echo $inserttime?></a></td>
			</tr>
		</thead>
	<?php
		if(mysql_num_rows($selectlogserver)>0){
			$i=0;
			while ($row = mysql_fetch_array($selectlogserver)){
				if ( $i >= $page_start ){?>
			<tr>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;width: 4%;"><?php echo $i+1?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[email] ?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_ip] ?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_name]?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[version]?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[status]?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[server_time]?></td>
					<td align="center" style="background: white;color: #5D5D5D;font-weight: normal;"><?php echo $row[ins_time]?></td>
				</tr>
		<?php
				}
					$i++;
					if ($i >= $page_end){
						break;
					}
				}
			}
		?>
		
		<tr>
					<td colspan="8" class="rf-dt-shdr-c">
						<span style="padding:1px; display: inline-block;">
													
							<?php if ( $number_of_page > 1 ) 
							{ 
								if ($page==1)
									$p=2;
								else if ($page==$number_of_page)
									$p=$number_of_page-1;
								else $p=$page;
								if($page!=1){?>
									<a onclick="sortandpagingLogServer(<?=1?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
									<a onclick="sortandpagingLogServer(<?=($page-1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')"><span class='button_next'><?php echo "<<";?></span> </a>
								<?php  }
								else{
									echo "<span class='button_next'><<<</span> "; 
									echo "<span class='button_next'><<</span> ";
								}
								for ( $i = $p-1; $i <= $p+1; $i++ ) {	
										if ($i<=$number_of_page && $i>0)
										
											if ($i==$page){
												echo "<span class='button_next'><b>".$i."</b></span>"; 
											}else{
											?>
												<a onclick="sortandpagingLogServer(<?=$i?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')"><span class="button_next">
												<?php 
												echo $i;
												?>
												</span> </a>
												<?php 
											}
										?>
									
								<?php 
										}
									
									if($page!=$number_of_page){ ?>
										<a onclick="sortandpagingLogServer(<?=($page+1)?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')"><span class='button_next'><?php echo ">>";?></span> </a>
										<a onclick="sortandpagingLogServer(<?=$number_of_page?>,'<?=$str?>',0,'<?=$search?>','<?=$_REQUEST['from']?>','<?=$_REQUEST['to']?>','<?=$lstatus?>','<?=$datecurrent?>','<?=$day2?>','<?=$day7?>','<?=$onemonth?>','<?=$searchhostnameauto?>')"><span class='button_next'><?php echo ">>>";?></span> </a>
									<?php }
									else{
										echo "<span class='button_next'>>></span> ";
										echo "<span class='button_next'>>>></span> ";
									}
								}
							
								
								?>
																					
						</span>
					</td>
				</tr>